// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"server/components/models/ent/forecast"
	"server/components/models/ent/predicate"
	"server/components/models/ent/region"
	"server/components/models/ent/weather"
	"time"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// WeatherUpdate is the builder for updating Weather entities.
type WeatherUpdate struct {
	config
	hooks    []Hook
	mutation *WeatherMutation
}

// Where appends a list predicates to the WeatherUpdate builder.
func (wu *WeatherUpdate) Where(ps ...predicate.Weather) *WeatherUpdate {
	wu.mutation.Where(ps...)
	return wu
}

// SetTemperature sets the "temperature" field.
func (wu *WeatherUpdate) SetTemperature(f float64) *WeatherUpdate {
	wu.mutation.ResetTemperature()
	wu.mutation.SetTemperature(f)
	return wu
}

// SetNillableTemperature sets the "temperature" field if the given value is not nil.
func (wu *WeatherUpdate) SetNillableTemperature(f *float64) *WeatherUpdate {
	if f != nil {
		wu.SetTemperature(*f)
	}
	return wu
}

// AddTemperature adds f to the "temperature" field.
func (wu *WeatherUpdate) AddTemperature(f float64) *WeatherUpdate {
	wu.mutation.AddTemperature(f)
	return wu
}

// SetHumidity sets the "humidity" field.
func (wu *WeatherUpdate) SetHumidity(f float64) *WeatherUpdate {
	wu.mutation.ResetHumidity()
	wu.mutation.SetHumidity(f)
	return wu
}

// SetNillableHumidity sets the "humidity" field if the given value is not nil.
func (wu *WeatherUpdate) SetNillableHumidity(f *float64) *WeatherUpdate {
	if f != nil {
		wu.SetHumidity(*f)
	}
	return wu
}

// AddHumidity adds f to the "humidity" field.
func (wu *WeatherUpdate) AddHumidity(f float64) *WeatherUpdate {
	wu.mutation.AddHumidity(f)
	return wu
}

// SetWindSpeed sets the "windSpeed" field.
func (wu *WeatherUpdate) SetWindSpeed(f float64) *WeatherUpdate {
	wu.mutation.ResetWindSpeed()
	wu.mutation.SetWindSpeed(f)
	return wu
}

// SetNillableWindSpeed sets the "windSpeed" field if the given value is not nil.
func (wu *WeatherUpdate) SetNillableWindSpeed(f *float64) *WeatherUpdate {
	if f != nil {
		wu.SetWindSpeed(*f)
	}
	return wu
}

// AddWindSpeed adds f to the "windSpeed" field.
func (wu *WeatherUpdate) AddWindSpeed(f float64) *WeatherUpdate {
	wu.mutation.AddWindSpeed(f)
	return wu
}

// SetWeatherCondition sets the "weatherCondition" field.
func (wu *WeatherUpdate) SetWeatherCondition(wc weather.WeatherCondition) *WeatherUpdate {
	wu.mutation.SetWeatherCondition(wc)
	return wu
}

// SetNillableWeatherCondition sets the "weatherCondition" field if the given value is not nil.
func (wu *WeatherUpdate) SetNillableWeatherCondition(wc *weather.WeatherCondition) *WeatherUpdate {
	if wc != nil {
		wu.SetWeatherCondition(*wc)
	}
	return wu
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (wu *WeatherUpdate) SetPrecipitationAmount(f float64) *WeatherUpdate {
	wu.mutation.ResetPrecipitationAmount()
	wu.mutation.SetPrecipitationAmount(f)
	return wu
}

// SetNillablePrecipitationAmount sets the "precipitationAmount" field if the given value is not nil.
func (wu *WeatherUpdate) SetNillablePrecipitationAmount(f *float64) *WeatherUpdate {
	if f != nil {
		wu.SetPrecipitationAmount(*f)
	}
	return wu
}

// AddPrecipitationAmount adds f to the "precipitationAmount" field.
func (wu *WeatherUpdate) AddPrecipitationAmount(f float64) *WeatherUpdate {
	wu.mutation.AddPrecipitationAmount(f)
	return wu
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (wu *WeatherUpdate) SetMeasurementDateTime(t time.Time) *WeatherUpdate {
	wu.mutation.SetMeasurementDateTime(t)
	return wu
}

// SetNillableMeasurementDateTime sets the "measurementDateTime" field if the given value is not nil.
func (wu *WeatherUpdate) SetNillableMeasurementDateTime(t *time.Time) *WeatherUpdate {
	if t != nil {
		wu.SetMeasurementDateTime(*t)
	}
	return wu
}

// SetRegionID sets the "region" edge to the Region entity by ID.
func (wu *WeatherUpdate) SetRegionID(id int64) *WeatherUpdate {
	wu.mutation.SetRegionID(id)
	return wu
}

// SetNillableRegionID sets the "region" edge to the Region entity by ID if the given value is not nil.
func (wu *WeatherUpdate) SetNillableRegionID(id *int64) *WeatherUpdate {
	if id != nil {
		wu = wu.SetRegionID(*id)
	}
	return wu
}

// SetRegion sets the "region" edge to the Region entity.
func (wu *WeatherUpdate) SetRegion(r *Region) *WeatherUpdate {
	return wu.SetRegionID(r.ID)
}

// AddForecastIDs adds the "forecast" edge to the Forecast entity by IDs.
func (wu *WeatherUpdate) AddForecastIDs(ids ...int64) *WeatherUpdate {
	wu.mutation.AddForecastIDs(ids...)
	return wu
}

// AddForecast adds the "forecast" edges to the Forecast entity.
func (wu *WeatherUpdate) AddForecast(f ...*Forecast) *WeatherUpdate {
	ids := make([]int64, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return wu.AddForecastIDs(ids...)
}

// Mutation returns the WeatherMutation object of the builder.
func (wu *WeatherUpdate) Mutation() *WeatherMutation {
	return wu.mutation
}

// ClearRegion clears the "region" edge to the Region entity.
func (wu *WeatherUpdate) ClearRegion() *WeatherUpdate {
	wu.mutation.ClearRegion()
	return wu
}

// ClearForecast clears all "forecast" edges to the Forecast entity.
func (wu *WeatherUpdate) ClearForecast() *WeatherUpdate {
	wu.mutation.ClearForecast()
	return wu
}

// RemoveForecastIDs removes the "forecast" edge to Forecast entities by IDs.
func (wu *WeatherUpdate) RemoveForecastIDs(ids ...int64) *WeatherUpdate {
	wu.mutation.RemoveForecastIDs(ids...)
	return wu
}

// RemoveForecast removes "forecast" edges to Forecast entities.
func (wu *WeatherUpdate) RemoveForecast(f ...*Forecast) *WeatherUpdate {
	ids := make([]int64, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return wu.RemoveForecastIDs(ids...)
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (wu *WeatherUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (wu *WeatherUpdate) SaveX(ctx context.Context) int {
	affected, err := wu.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (wu *WeatherUpdate) Exec(ctx context.Context) error {
	_, err := wu.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (wu *WeatherUpdate) ExecX(ctx context.Context) {
	if err := wu.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (wu *WeatherUpdate) check() error {
	if v, ok := wu.mutation.Humidity(); ok {
		if err := weather.HumidityValidator(v); err != nil {
			return &ValidationError{Name: "humidity", err: fmt.Errorf(`ent: validator failed for field "Weather.humidity": %w`, err)}
		}
	}
	if v, ok := wu.mutation.WindSpeed(); ok {
		if err := weather.WindSpeedValidator(v); err != nil {
			return &ValidationError{Name: "windSpeed", err: fmt.Errorf(`ent: validator failed for field "Weather.windSpeed": %w`, err)}
		}
	}
	if v, ok := wu.mutation.WeatherCondition(); ok {
		if err := weather.WeatherConditionValidator(v); err != nil {
			return &ValidationError{Name: "weatherCondition", err: fmt.Errorf(`ent: validator failed for field "Weather.weatherCondition": %w`, err)}
		}
	}
	if v, ok := wu.mutation.PrecipitationAmount(); ok {
		if err := weather.PrecipitationAmountValidator(v); err != nil {
			return &ValidationError{Name: "precipitationAmount", err: fmt.Errorf(`ent: validator failed for field "Weather.precipitationAmount": %w`, err)}
		}
	}
	return nil
}

func (wu *WeatherUpdate) sqlSave(ctx context.Context) (n int, err error) {
	if err := wu.check(); err != nil {
		return n, err
	}
	_spec := sqlgraph.NewUpdateSpec(weather.Table, weather.Columns, sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64))
	if ps := wu.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wu.mutation.Temperature(); ok {
		_spec.SetField(weather.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.AddedTemperature(); ok {
		_spec.AddField(weather.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.Humidity(); ok {
		_spec.SetField(weather.FieldHumidity, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.AddedHumidity(); ok {
		_spec.AddField(weather.FieldHumidity, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.WindSpeed(); ok {
		_spec.SetField(weather.FieldWindSpeed, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.AddedWindSpeed(); ok {
		_spec.AddField(weather.FieldWindSpeed, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.WeatherCondition(); ok {
		_spec.SetField(weather.FieldWeatherCondition, field.TypeEnum, value)
	}
	if value, ok := wu.mutation.PrecipitationAmount(); ok {
		_spec.SetField(weather.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.AddedPrecipitationAmount(); ok {
		_spec.AddField(weather.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if value, ok := wu.mutation.MeasurementDateTime(); ok {
		_spec.SetField(weather.FieldMeasurementDateTime, field.TypeTime, value)
	}
	if wu.mutation.RegionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   weather.RegionTable,
			Columns: []string{weather.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.RegionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   weather.RegionTable,
			Columns: []string{weather.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wu.mutation.ForecastCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.RemovedForecastIDs(); len(nodes) > 0 && !wu.mutation.ForecastCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wu.mutation.ForecastIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{weather.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	wu.mutation.done = true
	return n, nil
}

// WeatherUpdateOne is the builder for updating a single Weather entity.
type WeatherUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *WeatherMutation
}

// SetTemperature sets the "temperature" field.
func (wuo *WeatherUpdateOne) SetTemperature(f float64) *WeatherUpdateOne {
	wuo.mutation.ResetTemperature()
	wuo.mutation.SetTemperature(f)
	return wuo
}

// SetNillableTemperature sets the "temperature" field if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillableTemperature(f *float64) *WeatherUpdateOne {
	if f != nil {
		wuo.SetTemperature(*f)
	}
	return wuo
}

// AddTemperature adds f to the "temperature" field.
func (wuo *WeatherUpdateOne) AddTemperature(f float64) *WeatherUpdateOne {
	wuo.mutation.AddTemperature(f)
	return wuo
}

// SetHumidity sets the "humidity" field.
func (wuo *WeatherUpdateOne) SetHumidity(f float64) *WeatherUpdateOne {
	wuo.mutation.ResetHumidity()
	wuo.mutation.SetHumidity(f)
	return wuo
}

// SetNillableHumidity sets the "humidity" field if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillableHumidity(f *float64) *WeatherUpdateOne {
	if f != nil {
		wuo.SetHumidity(*f)
	}
	return wuo
}

// AddHumidity adds f to the "humidity" field.
func (wuo *WeatherUpdateOne) AddHumidity(f float64) *WeatherUpdateOne {
	wuo.mutation.AddHumidity(f)
	return wuo
}

// SetWindSpeed sets the "windSpeed" field.
func (wuo *WeatherUpdateOne) SetWindSpeed(f float64) *WeatherUpdateOne {
	wuo.mutation.ResetWindSpeed()
	wuo.mutation.SetWindSpeed(f)
	return wuo
}

// SetNillableWindSpeed sets the "windSpeed" field if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillableWindSpeed(f *float64) *WeatherUpdateOne {
	if f != nil {
		wuo.SetWindSpeed(*f)
	}
	return wuo
}

// AddWindSpeed adds f to the "windSpeed" field.
func (wuo *WeatherUpdateOne) AddWindSpeed(f float64) *WeatherUpdateOne {
	wuo.mutation.AddWindSpeed(f)
	return wuo
}

// SetWeatherCondition sets the "weatherCondition" field.
func (wuo *WeatherUpdateOne) SetWeatherCondition(wc weather.WeatherCondition) *WeatherUpdateOne {
	wuo.mutation.SetWeatherCondition(wc)
	return wuo
}

// SetNillableWeatherCondition sets the "weatherCondition" field if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillableWeatherCondition(wc *weather.WeatherCondition) *WeatherUpdateOne {
	if wc != nil {
		wuo.SetWeatherCondition(*wc)
	}
	return wuo
}

// SetPrecipitationAmount sets the "precipitationAmount" field.
func (wuo *WeatherUpdateOne) SetPrecipitationAmount(f float64) *WeatherUpdateOne {
	wuo.mutation.ResetPrecipitationAmount()
	wuo.mutation.SetPrecipitationAmount(f)
	return wuo
}

// SetNillablePrecipitationAmount sets the "precipitationAmount" field if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillablePrecipitationAmount(f *float64) *WeatherUpdateOne {
	if f != nil {
		wuo.SetPrecipitationAmount(*f)
	}
	return wuo
}

// AddPrecipitationAmount adds f to the "precipitationAmount" field.
func (wuo *WeatherUpdateOne) AddPrecipitationAmount(f float64) *WeatherUpdateOne {
	wuo.mutation.AddPrecipitationAmount(f)
	return wuo
}

// SetMeasurementDateTime sets the "measurementDateTime" field.
func (wuo *WeatherUpdateOne) SetMeasurementDateTime(t time.Time) *WeatherUpdateOne {
	wuo.mutation.SetMeasurementDateTime(t)
	return wuo
}

// SetNillableMeasurementDateTime sets the "measurementDateTime" field if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillableMeasurementDateTime(t *time.Time) *WeatherUpdateOne {
	if t != nil {
		wuo.SetMeasurementDateTime(*t)
	}
	return wuo
}

// SetRegionID sets the "region" edge to the Region entity by ID.
func (wuo *WeatherUpdateOne) SetRegionID(id int64) *WeatherUpdateOne {
	wuo.mutation.SetRegionID(id)
	return wuo
}

// SetNillableRegionID sets the "region" edge to the Region entity by ID if the given value is not nil.
func (wuo *WeatherUpdateOne) SetNillableRegionID(id *int64) *WeatherUpdateOne {
	if id != nil {
		wuo = wuo.SetRegionID(*id)
	}
	return wuo
}

// SetRegion sets the "region" edge to the Region entity.
func (wuo *WeatherUpdateOne) SetRegion(r *Region) *WeatherUpdateOne {
	return wuo.SetRegionID(r.ID)
}

// AddForecastIDs adds the "forecast" edge to the Forecast entity by IDs.
func (wuo *WeatherUpdateOne) AddForecastIDs(ids ...int64) *WeatherUpdateOne {
	wuo.mutation.AddForecastIDs(ids...)
	return wuo
}

// AddForecast adds the "forecast" edges to the Forecast entity.
func (wuo *WeatherUpdateOne) AddForecast(f ...*Forecast) *WeatherUpdateOne {
	ids := make([]int64, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return wuo.AddForecastIDs(ids...)
}

// Mutation returns the WeatherMutation object of the builder.
func (wuo *WeatherUpdateOne) Mutation() *WeatherMutation {
	return wuo.mutation
}

// ClearRegion clears the "region" edge to the Region entity.
func (wuo *WeatherUpdateOne) ClearRegion() *WeatherUpdateOne {
	wuo.mutation.ClearRegion()
	return wuo
}

// ClearForecast clears all "forecast" edges to the Forecast entity.
func (wuo *WeatherUpdateOne) ClearForecast() *WeatherUpdateOne {
	wuo.mutation.ClearForecast()
	return wuo
}

// RemoveForecastIDs removes the "forecast" edge to Forecast entities by IDs.
func (wuo *WeatherUpdateOne) RemoveForecastIDs(ids ...int64) *WeatherUpdateOne {
	wuo.mutation.RemoveForecastIDs(ids...)
	return wuo
}

// RemoveForecast removes "forecast" edges to Forecast entities.
func (wuo *WeatherUpdateOne) RemoveForecast(f ...*Forecast) *WeatherUpdateOne {
	ids := make([]int64, len(f))
	for i := range f {
		ids[i] = f[i].ID
	}
	return wuo.RemoveForecastIDs(ids...)
}

// Where appends a list predicates to the WeatherUpdate builder.
func (wuo *WeatherUpdateOne) Where(ps ...predicate.Weather) *WeatherUpdateOne {
	wuo.mutation.Where(ps...)
	return wuo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (wuo *WeatherUpdateOne) Select(field string, fields ...string) *WeatherUpdateOne {
	wuo.fields = append([]string{field}, fields...)
	return wuo
}

// Save executes the query and returns the updated Weather entity.
func (wuo *WeatherUpdateOne) Save(ctx context.Context) (*Weather, error) {
	return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (wuo *WeatherUpdateOne) SaveX(ctx context.Context) *Weather {
	node, err := wuo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (wuo *WeatherUpdateOne) Exec(ctx context.Context) error {
	_, err := wuo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (wuo *WeatherUpdateOne) ExecX(ctx context.Context) {
	if err := wuo.Exec(ctx); err != nil {
		panic(err)
	}
}

// check runs all checks and user-defined validators on the builder.
func (wuo *WeatherUpdateOne) check() error {
	if v, ok := wuo.mutation.Humidity(); ok {
		if err := weather.HumidityValidator(v); err != nil {
			return &ValidationError{Name: "humidity", err: fmt.Errorf(`ent: validator failed for field "Weather.humidity": %w`, err)}
		}
	}
	if v, ok := wuo.mutation.WindSpeed(); ok {
		if err := weather.WindSpeedValidator(v); err != nil {
			return &ValidationError{Name: "windSpeed", err: fmt.Errorf(`ent: validator failed for field "Weather.windSpeed": %w`, err)}
		}
	}
	if v, ok := wuo.mutation.WeatherCondition(); ok {
		if err := weather.WeatherConditionValidator(v); err != nil {
			return &ValidationError{Name: "weatherCondition", err: fmt.Errorf(`ent: validator failed for field "Weather.weatherCondition": %w`, err)}
		}
	}
	if v, ok := wuo.mutation.PrecipitationAmount(); ok {
		if err := weather.PrecipitationAmountValidator(v); err != nil {
			return &ValidationError{Name: "precipitationAmount", err: fmt.Errorf(`ent: validator failed for field "Weather.precipitationAmount": %w`, err)}
		}
	}
	return nil
}

func (wuo *WeatherUpdateOne) sqlSave(ctx context.Context) (_node *Weather, err error) {
	if err := wuo.check(); err != nil {
		return _node, err
	}
	_spec := sqlgraph.NewUpdateSpec(weather.Table, weather.Columns, sqlgraph.NewFieldSpec(weather.FieldID, field.TypeInt64))
	id, ok := wuo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Weather.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := wuo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, weather.FieldID)
		for _, f := range fields {
			if !weather.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != weather.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := wuo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := wuo.mutation.Temperature(); ok {
		_spec.SetField(weather.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.AddedTemperature(); ok {
		_spec.AddField(weather.FieldTemperature, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.Humidity(); ok {
		_spec.SetField(weather.FieldHumidity, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.AddedHumidity(); ok {
		_spec.AddField(weather.FieldHumidity, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.WindSpeed(); ok {
		_spec.SetField(weather.FieldWindSpeed, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.AddedWindSpeed(); ok {
		_spec.AddField(weather.FieldWindSpeed, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.WeatherCondition(); ok {
		_spec.SetField(weather.FieldWeatherCondition, field.TypeEnum, value)
	}
	if value, ok := wuo.mutation.PrecipitationAmount(); ok {
		_spec.SetField(weather.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.AddedPrecipitationAmount(); ok {
		_spec.AddField(weather.FieldPrecipitationAmount, field.TypeFloat64, value)
	}
	if value, ok := wuo.mutation.MeasurementDateTime(); ok {
		_spec.SetField(weather.FieldMeasurementDateTime, field.TypeTime, value)
	}
	if wuo.mutation.RegionCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   weather.RegionTable,
			Columns: []string{weather.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.RegionIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   weather.RegionTable,
			Columns: []string{weather.RegionColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if wuo.mutation.ForecastCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.RemovedForecastIDs(); len(nodes) > 0 && !wuo.mutation.ForecastCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := wuo.mutation.ForecastIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.O2M,
			Inverse: false,
			Table:   weather.ForecastTable,
			Columns: []string{weather.ForecastColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(forecast.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Weather{config: wuo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{weather.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	wuo.mutation.done = true
	return _node, nil
}
